"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useFullScreen;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
var doc = document;
var _document = document,
  documentElement = _document.documentElement;
var requestFullscreen = function requestFullscreen(elem) {
  var method = documentElement.requestFullscreen ||
  // W3C
  // @ts-ignore
  documentElement.webkitRequestFullscreen ||
  // Chrome等
  // @ts-ignore
  documentElement.mozRequestFullScreen ||
  // FireFox
  // @ts-ignore
  documentElement.msRequestFullscreen; // IE11
  method === null || method === void 0 ? void 0 : method.call(elem);
};
var exitFullscreen = function exitFullscreen() {
  var method = doc.exitFullscreen ||
  // W3C
  doc.mozCancelFullScreen ||
  // firefox
  doc.webkitExitFullscreen ||
  // Chrome等
  doc.msExitFullscreen; // IE11
  method === null || method === void 0 ? void 0 : method.call(doc);
};
/**
 * 全屏切换
 * @returns
 */
function useFullScreen() {
  var _useState = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    isFullScreen = _useState2[0],
    setIsFullScreen = _useState2[1];
  /**
   * 切换全屏展示
   */
  var toggle = (0, _react.useCallback)(function (elem) {
    if (isFullScreen) {
      exitFullscreen();
      setIsFullScreen(false);
    } else {
      requestFullscreen(elem);
      setIsFullScreen(true);
    }
  }, [isFullScreen]);
  return [isFullScreen, toggle];
}